1 module core.memory;
2 
3 struct GC
4 {
5     static void* addrOf(void* addr)@trusted pure nothrow @nogc {return addr;}
6     static void free(void* addr, string f = __FILE__, size_t l = __LINE__ ) @trusted nothrow @nogc pure
7     {
8         pureFree(addr, f, l);
9     }
10 
11     static size_t extend(void* ptr, size_t max, size_t desiredExtensionInSize, const TypeInfo ti =  null) pure nothrow
12     {
13         import core.arsd.memory_allocation;
14         import rt.hooks;
15         pureRealloc(cast(ubyte[])ptr[0..0], desiredExtensionInSize);
16         return desiredExtensionInSize;
17     }
18 
19     static BlkInfo qalloc(size_t sz, uint ba = 0, const scope TypeInfo ti = null) pure nothrow
20     {
21         import core.arsd.memory_allocation;
22         import rt.hooks;
23         return BlkInfo(pureMalloc(sz).ptr, sz);
24     }
25 
26 
27 
28     enum BlkAttr : uint
29     {
30         NONE        = 0b0000_0000, /// No attributes set.
31         FINALIZE    = 0b0000_0001, /// Finalize the data in this block on collect.
32         NO_SCAN     = 0b0000_0010, /// Do not scan through this block on collect.
33         NO_MOVE     = 0b0000_0100, /// Do not move this memory block on collect.
34         APPENDABLE  = 0b0000_1000,
35         NO_INTERIOR = 0b0001_0000,
36         STRUCTFINAL = 0b0010_0000, // the block has a finalizer for (an array of) structs
37     }
38 }
39 
40 
41 struct BlkInfo
42 {
43     void*  base;
44     size_t size;
45     uint   attr;
46 }
47 
48 void pureFree(void* addr, string f = __FILE__, size_t l = __LINE__) pure nothrow @trusted @nogc
49 {
50     import rt.hooks;
51     alias pureFreeT = extern(C) void function(void* addr, string f, size_t l) pure nothrow @trusted @nogc;
52     auto freeAddr = cast(pureFreeT)&free;
53     freeAddr(addr, f, l);
54 }
55 
56 enum pageSize = 516;